<template>
    <PageWrapper>
      <n-card :bordered="false" class="mb-3 proCard">
        <n-space align="center">
          <n-input-group style="width: 1400px">
            <div style="margin-left: 10px !important;display: flex;align-items: center;">
                <n-input
                style="width: 100%;margin-left: 20px;"
                v-model:value="params.danhao"
                clearable
                placeholder="请输入流水号"
                @keyup.enter="reloadTable"
                />
            </div>
            <div style="margin-left: 10px !important;display: flex;align-items: center;">
                <n-input
                style="width: 100%;margin-left: 20px;"
                v-model:value="params.agent_name"
                clearable
                placeholder="请输入代理商名称"
                @keyup.enter="reloadTable"
                />
            </div>
            <div style="margin-left: 10px !important;display: flex;align-items: center;">
                <n-input
                style="width: 100%;margin-left: 20px;"
                v-model:value="params.bussiness_name"
                clearable
                placeholder="请输入商户名称"
                @keyup.enter="reloadTable"
                />
            </div>
            <div style="margin-left: 10px !important;display: flex;align-items: center;">
                <n-input
                style="width: 100%;margin-left: 20px;"
                v-model:value="params.yuangong_name"
                clearable
                placeholder="请输入员工名称"
                @keyup.enter="reloadTable"
                />
            </div>
            <div style="margin-left: 20px !important;display: flex;align-items: center;">
                <n-select v-model:value="params.pingtai" placeholder="请选择平台" style="width: 200px;" :options="optionspt" clearable />
            </div>
            <div style="margin-left: 30px !important;display: flex;align-items: center;">
              <n-date-picker v-model:value="range" type="daterange"  @update:value="onChange4" clearable />
            </div>
            <n-button type="primary" style="margin-left: 40px !important;" @click="reloadTable">
              <template #icon>
                <n-icon>
                  <SearchOutlined />
                </n-icon>
              </template>
              查询
            </n-button>
          </n-input-group>
        </n-space>
        <div class="wenzi">
          <span class="shouyi">平台收益:</span><span class="money">{{orderData.platform_money}}元</span>
          <span class="yue">代理商收益:</span><span class="money">{{orderData.agent_money}}元</span>
          <span class="yue">员工收益:</span><span class="money">{{orderData.yuangong_money}}元</span>
          <span class="yue">商户收益:</span><span class="money">{{orderData.bussiness_money}}元</span>
        </div>
      </n-card>
      <n-card :bordered="false" class="proCard">
        <BasicTable
          :columns="columns"
          :request="loadDataTable"
          :row-key="(row) => row.id"
          ref="basicTableRef"
          virtual-scroll
        >
        </BasicTable>
      </n-card>

    </PageWrapper>
  </template>
  
  <script lang="ts" setup>
    import { reactive, ref, onMounted } from 'vue';
    import { BasicTable } from '@/components/Table';
    import { SearchOutlined } from '@vicons/antd';
    import { columns } from './columns';
    import { orderlist,orderdata } from '@/api/order/index';

    const basicTableRef = ref();
    const tableData = ref();
    const orderData = ref({
      platform_money: 0,
      agent_money: 0,
      yuangong_money: 0,
      bussiness_money: 0,
    });
    const range = ref<[number, number]>();
  
    const params = reactive({
      danhao: '',
      sdate: '',
      edate: '',
      agent_name: '',
      bussiness_name: '',
      yuangong_name: '',
      pingtai: null,
    });

    const optionspt = ref([
      {
        label: "微信小程序",
        value: 0,
      },
      {
        label: '支付宝小程序',
        value: 1
      },
      {
        label: '抖音小程序',
        value: 2
      }
      
    ])
  
    //列表数据
    const loadDataTable = async (res) => {
      const result = await orderlist({ ...params, ...res });
      tableData.value = result.list;
      return result;
    };
    
    //加载表格
    function reloadTable() {
      basicTableRef.value.reload();

      orderdata({ ...params }).then((res) => {
        orderData.value = res;
      });
    }

    function onChange4(v: number){
      if(v != null){
        params.sdate = v[0];
        params.edate = v[1];
      }else{
        params.sdate = '';
        params.edate = '';
      }
    }

    onMounted(async () => {
      const res1 = await orderdata({ ...params });
      orderData.value = res1
    });
  
  </script>
  
<style lang="less" scoped>
  .wenzi{
    margin-top: 20px;
    margin-left: 2%;
    font-size: 18px;

    .shouyi{
      margin-right: 10px;
    }

    .yue{
      margin-left: 30px;
      margin-right: 10px;
    }

    .money{
      color: red;
      font-weight: 700;
    }
  }

</style>
  